lexer grammar AnalizadorEjemplo;

options {
  language = Java;

}



@lexer::header{package PL.practica4vs2;
import java.util.ArrayList;}

@lexer::members {
public class MyToken extends CommonToken {
    String nFile; // custom field
    public MyToken(CharStream input, int type, int channel, int start, int stop){
        super(input, type, channel, start, stop);
        nFile = "";
    }
    public void setNfile (String s){nFile= s;}
    public String getNfile (){return nFile;}
    public String toString() { return super.toString()+",nombre fichero="+nFile; }
}


ArrayList <RecognitionException> errores = new ArrayList<RecognitionException>();

public boolean listaVacia (){
    if (errores.isEmpty()){
      return true;
    }else
      return false;
}

public ArrayList getListaErrores(){return errores;}

@Override
public void reportError (RecognitionException e){
  errores.add(e);
}

 
// override standard token emission
public Token emit() {
    MyToken t =
        new MyToken(input, state.type, state.channel,
                    state.tokenStartCharIndex, getCharIndex()-1);
    t.setLine(state.tokenStartLine);
    t.setText(state.text);
    t.setCharPositionInLine(state.tokenStartCharPositionInLine);
    t.nFile = this.getSourceName();
    emit(t);
    return t;
    }
}
 
  fragment NUEVA_LINEA: '\r\n' ;
  BLANCO: (' '|'\t'|NUEVA_LINEA) {skip();};
  fragment DIGITO: '0'..'9';
  fragment LETRA : ('a'..'z')|('A'..'Z')|'_';
  NUMERO: (DIGITO)+('.'(DIGITO)+)?;
  OPERADOR: '+'|'-'|'/'|'*';
  PARENTESIS: '('|')';
  SEPARADOR: ';';
  COMENTARIOLINEA : '//' (options {greedy=false;}:.)* '\r\n' {skip();};
  ID : LETRA(LETRA|DIGITO)*;
 COMENTARIO: '/*' ('*' ~('/')| ~ ('*') )* ('*/'|'**/') {skip();};
 